"""
=================================================
@Author: Zhenzhou Liu
@Date: 2025-01-14
@Description：
==================================================
"""
from collections import deque


class Pet:
    def getType(self) -> str:
        pass

    def getId(self) -> int:
        pass

    def getCount(self) -> int:
        pass


class Cat(Pet):
    def __init__(self, type: str, id: int, count: int):
        self.type = type
        self.id = id
        self.count = count

    def getType(self) -> str:
        return self.type

    def getId(self) -> int:
        return self.id

    def getCount(self) -> int:
        return self.count

class Dog(Pet):
    def __init__(self, type: str, id: int, count: int):
        self.type = type
        self.id = id
        self.count = count

    def getType(self) -> str:
        return self.type

    def getId(self) -> int:
        return self.id

    def getCount(self) -> int:
        return self.count

class CatDogQueue:
    def __init__(self):
        self.dog_queue: deque[Dog] = deque([])
        self.cat_queue: deque[Cat] = deque([])

    def add_pet(self, pet: Pet):
        if "dog" == pet.getType():
            self.dog_queue.append(pet)
        else:
            self.cat_queue.append(pet)

    def poll_dog(self) -> Dog:
        return self.dog_queue.popleft()

    def poll_cat(self) -> Cat:
        return self.cat_queue.popleft()

    def poll_all(self) -> Pet:
        if self.cat_queue and self.dog_queue:
            if self.dog_queue[0].getCount() < self.cat_queue[0].getCount():
                return self.dog_queue.popleft()
            else:
                return self.cat_queue.popleft()
        elif self.dog_queue:
            return self.dog_queue.popleft()
        else:
            return self.cat_queue.popleft()

    def is_empty(self):
        return not self.dog_queue and not self.cat_queue

    def is_dog_empty(self):
        return not self.dog_queue

    def is_cat_empty(self):
        return not self.cat_queue

if __name__ == '__main__':
    n = int(input())
    output = []
    count = 0
    queue = CatDogQueue()
    for _ in range(n):
        line = input().strip()
        parts = line.split()
        opt = parts[0]

        if opt == "add":
            type = parts[1]
            id = int(parts[2])
            count += 1
            if type == "dog":
                queue.add_pet(Dog("dog", id, count))
            else:
                queue.add_pet(Cat("cat", id, count))

        elif opt == "pollAll":
            while not queue.is_empty():
                pet = queue.poll_all()
                output.append(f'{pet.getType()} {pet.getId()}')

        elif opt == "pollDog":
            while not queue.is_dog_empty():
                dog = queue.poll_dog()
                output.append(f"dog {dog.getId()}")

        elif opt == "pollCat":
            while not queue.is_cat_empty():
                cat = queue.poll_cat()
                output.append(f"cat {cat.getId()}")

        elif opt == "isEmpty":
            output.append("yes" if queue.is_empty() else "no")

        elif opt == "isDogEmpty":
            output.append("yes" if queue.is_dog_empty() else "no")

        elif opt == "isCatEmpty":
            output.append("yes" if queue.is_cat_empty() else "no")

    print('\n'.join(output))